package com.hotacorp.opencloud.authserver.bean;

import java.util.ArrayList;
import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.hotacorp.opencloud.common.authcommon.SysUserBean;

/**
 * OAuth2用户明细接口实现
 * @author lwg
 *
 */
public class SysUserDetail implements UserDetails {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private SysUserBean sysUserBean;
	
	public SysUserDetail(SysUserBean sysUserBean) {
		super();
		this.sysUserBean = sysUserBean;
	}

	public void setSysUserBean(SysUserBean sysUserBean) {
		this.sysUserBean = sysUserBean;
	}

	public SysUserBean getSysUserBean() {
		return sysUserBean;
	}

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		Collection<GrantedAuthority> dddAuthorities = new ArrayList<>();
		sysUserBean.getAuthoritys().forEach(action->{
					dddAuthorities.add(new GrantedAuthority() {
						private static final long serialVersionUID = 1L;
						public String getAuthority() {return action;}
						});
			});
		return dddAuthorities;
	}

	@Override
	public String getPassword() {
		return sysUserBean.getPassword();
	}

	@Override
	public String getUsername() {
		return sysUserBean.getUsername();
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return sysUserBean.isEnabled();
	}
	
	public Long getDepid() {
		return sysUserBean.getDepid();
	}
	
	public Long getTenantid() {
		return sysUserBean.getTenantid();
	}
	
	public Long getUserid() {
		return sysUserBean.getId();
	}
	
	public String getNickname() {
		return sysUserBean.getNickname();
	}

	public String getPhone() {
		return sysUserBean.getPhone();
	}

	@Override
	public String toString() {
		return "SysUserDetail [sysUserBean=" + sysUserBean + "]";
	}
	
	
	
}
